package com.acwing.partition4;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author `RKC`
 * @date 2022/1/25 15:32
 */
public class AC367学校网络 {

    private static final int N = 110, M = 10010;
    private static int[] h = new int[N], e = new int[M], ne = new int[M];

    private static int n = 0, m = 0, timestamp = 0, idx = 0, cnt = 0;
    private static Deque<Integer> stack = new ArrayDeque<>(N);
    private static boolean[] inStack = new boolean[N];
    private static int[] dfn = new int[N], low = new int[N], scc = new int[N], in = new int[N], out = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i <= n; i++) h[i] = -1;
        for (int i = 1; i <= n; i++) {
            String[] s = reader.readLine().split(" ");
            for (int j = 0; j < s.length; j++) {
                int v = Integer.parseInt(s[j]);
                if (v == 0) break;
                add(i, v);
            }
        }
        for (int i = 1; i <= n; i++) {
            if (dfn[i] == 0) tarjan(i);
        }
        //缩点，计算连通分量的入度
        for (int u = 1; u <= n; u++) {
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                if (scc[u] == scc[v]) continue;
                in[scc[v]]++;
                out[scc[u]]++;
            }
        }
        int a = 0, b = 0;
        for (int i = 1; i <= cnt; i++) {
            if (in[i] == 0) a++;
            if (out[i] == 0) b++;
        }
        writer.write(a + "\n");
        //如果本来就是一个强连通图，不需要加任何的新边
        if (cnt == 1) writer.write(0 + "\n");
        else writer.write(Math.max(a, b) + "\n");
        writer.flush();
    }

    private static void tarjan(int u) {
        dfn[u] = low[u] = ++timestamp;
        stack.addLast(u);
        inStack[u] = true;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (dfn[v] == 0) {
                tarjan(v);
                low[u] = Math.min(low[u], low[v]);
            } else if (inStack[v]) {
                low[u] = Math.min(low[u], dfn[v]);
            }
        }
        if (dfn[u] == low[u]) {
            cnt++;
            int v = -1;
            do {
                v = stack.pollLast();
                inStack[v] = false;
                scc[v] = cnt;
            } while (u != v);
        }
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
